<template>

    <ul class="animation">
        <li v-for="(item,index) in communication" class="message_li">
            <div class="info">
                <p>{{item.message}}</p>
                <img src="/img/common/tishi.png" alt="" title="新信息">
            </div>
        </li>
    </ul>


</template>
<script>
import api from "@/api";

export default {
    name: "MessagePopUp",
    data(){
      return{
          communication:[],
      }
    },
    mounted() {
        let message = JSON.parse(window.localStorage.getItem("message"));
        if(message){
            this.add_(message)
            window.localStorage.removeItem("message");

        }
    },
    methods:{
       add_(message){
           let i = 0;
               setInterval(()=>{
                   if(i === message.length){
                       return;
                   }
                   this.communication.push(message[i]);
                   i+=1;
               },1000)
       },

    }
}
</script>

<style scoped>
.animation{
    position: fixed;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    list-style: none;
    z-index: 9999999;
    transition: all .3s;
}
li{
    position: relative;
    min-height: 60px;
    margin-bottom: 8px;
    transition: all .3s;
    animation: move 1s ease-in-out 0s 1 forwards, disappear 1s ease-in-out 3s 1 forwards;
}
.info {
    height: 50px;
    width: 400px;
    background: rgba(242, 242, 243, 0.9);
    padding: 3px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1vw;
    color: #f1f5f4;
    border-radius: 0.4vw;
}
p{
    color: #8f8c8c;
    font-size: 15px;
    word-break: break-all;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}
.info p::before {
    display: inline-block;
    content: "新消息：";
    font-size: 15px;
    padding: 0 4px;
    color: #ee4f4f;

}

@keyframes move {
    0% {
      transform:translateY(0);
    }
    100% {
        transform:translateY(-20px);
    }
}

@keyframes disappear {
    0% {
        transform:translateY(-20px);
        opacity: 1;
    }
    100% {
        transform:translateY(-40px);
        opacity: 0;
        display: none;
    }
}
</style>